package sina;

import java.util.List;

public class B implements Runnable {
    private final List<Data> queue;
    private final int length;
    public B(List<Data> queue,int length) {
        this.queue = queue;
        this.length=length;
    }

    @Override
    public void run() {
        try {
            while (true){
                synchronized (queue){
                    if(queue.size()==length){
                        queue.notifyAll();
                        queue.wait();
                    }else {
                        Data data=new Data();
                        queue.add(data);
                    }
                }
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
